<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of PaymentRekap
 *
 * @author miyzan
 */
class PaymentRekap extends MY_FPDF {

    //put your code here
    var $judul;

    function setJudul($value) {
        $this->judul = $value;
    }

    function getthbl($thbl) {
        $th = substr($thbl, 0, 4);
        $bl = substr($thbl, 4, 2);
        if ($bl == '01')
            $bl = 'Januari';
        else if ($bl == '02')
            $bl = 'Februari';
        else if ($bl == '03')
            $bl = 'Maret';
        else if ($bl == '04')
            $bl = 'April';
        else if ($bl == '05')
            $bl = 'Mei';
        else if ($bl == '06')
            $bl = 'Juni';
        else if ($bl == '07')
            $bl = 'Juli';
        else if ($bl == '08')
            $bl = 'Agustus';
        else if ($bl == '09')
            $bl = 'September';
        else if ($bl == '10')
            $bl = 'Oktober';
        else if ($bl == '11')
            $bl = 'Nopember';
        else if ($bl == '12')
            $bl = 'Desember';
        return $bl . ' ' . $th;
    }

    function Header() {

//Logo
        $this->Image($this->logourl, 3, 3, 15);

//Arial bold 15
        $this->SetFont('Arial', 'B', 12);
        $this->SetTextColor(1, 50, 155);
        $this->SetY(8);
        $this->Cell(13);
        $this->Cell(70, 5, $this->namasekolah, 0);
        $this->Cell(117, 5, '', 0);
        $this->Ln(5);
        $this->SetFont('Arial', 'B', 8);
        $this->Cell(13);
        $this->Cell(70, 3, $this->alamat, 0);


        $this->SetFont('Arial', 'I', 8);
        $this->SetY(8);
        $this->Cell(157);
        $this->Cell(20, 3, 'Tanggal Cetak', 0, 0, 'L');
        $this->Cell(3, 3, ':', 0, 0, 'C');
        $this->Cell(20, 3, date('d/m/Y'), 0, 0, 'R');
        $this->Ln(3);
        $this->Cell(157);
        $this->Cell(20, 3, 'Waktu Cetak', 0, 0, 'L');
        $this->Cell(3, 3, ':', 0, 0, 'C');
        $this->Cell(20, 3, date('h:i:s'), 0, 0, 'R');
        $this->Ln(3);
        $this->Cell(157);
        $this->Cell(20, 3, 'Halaman', 0, 0, 'L');
        $this->Cell(3, 3, ':', 0, 0, 'C');
        $this->Cell(20, 3, $this->PageNo() . ' dari {nb}', 0, 0, 'R');
//        $this->Ln();
        $this->SetDrawColor(1, 50, 155);
        $this->SetLineWidth(.25);
        $this->Line(5, 19, 205, 19);

        $this->Ln(6);

        $this->SetTextColor(0, 0, 0);
        $this->SetX(5);
        $this->SetFont('Arial', 'B', 10);
        $this->Cell(0, 5, $this->judul, 0, 0, 'C');
        $this->Ln();
        $this->SetX(5);
        $this->SetFont('Arial', '', 10);
        if (count($this->dataheader) > 0) {
            $this->Cell(0, 5, $this->dataheader[0], 0, 0, 'C');
            $this->Ln();
            $this->SetFont('Arial', '', 8);
            $this->Cell(0, 5, $this->dataheader[1], 0, 0, 'C');
            $this->Ln();
        } else {
            $this->Cell(0, 5, '', 0, 0, 'C');
            $this->Ln();
        }
        $this->Ln(5);
    }

    function getcount_data($data, $where) {
        $total = 0;
        $tot = 0;
        foreach ($data as $value) {
            $tot = 0;
           
            $arr1=array();
            foreach ($value as $key => $v) {
                if(array_key_exists($key, $where)){                  
                       $arr1[$key]=$v;                  
                }                
            }
            $arr= array_intersect($arr1, $where);
            if(array_count_values($arr)==array_count_values($where)){
                $tot ++;
            }
            $total+=$tot;
        }
        return $total;
    }

    public function set_header_column($head, $w) {
        $alignhead = array_fill(0, count($w), "C");
        $borderhead = array_fill(0, count($w) - 1, 'TBL');
        array_push($borderhead, 1);
        $this->SetFont('Arial', 'B', 8);
        $this->SetX(5);
        for ($i = 0; $i < count($w); $i++) {
            $this->Cell($w[$i], 4, $head[$i], $borderhead[$i], 0, $alignhead[$i]);
        }
        $this->Ln();
    }

    public function get_header_column($groupbysql = NULL) {
        $retval = array();
        if ($groupbysql) {
            if ($groupbysql == 'rekening') {
                $retval = array(
                    'head' => array('Jenis_Biaya', 'Biaya', 'Pelunasan'),
                    'wh' => array(30, 30, 30),
                    'border' => array('TBL', 'TBL', 'TRBL'),
                    'align' => array('L', 'L', 'R'),
                    'keys' => array('jenis_biaya', 'biaya', 'pelunasan'),
                    'numbercell'=> array('pelunasan'),
                    'totalcell'=> array('pelunasan')
                );
            }
            if ($groupbysql == 'jenis') {
                $retval = array(
                    'head' => array('Biaya', 'Pelunasan'),
                    'wh' => array(30, 30),
                    'border' => array('TBL', 'TRBL'),
                    'align' => array( 'L', 'R'),
                    'keys' => array('biaya', 'pelunasan'),
                     'numbercell'=> array('pelunasan')
                );
            }
            if ($groupbysql == 'tglbayar') {
                $retval = array(
                    'head' => array('Jenis_Biaya', 'Biaya', 'Pelunasan'),
                    'wh' => array(80, 40, 30),
                    'border' => array('TBL', 'TBL', 1),
                    'align' => array('L', 'L', 'R'),
                    'keys' => array('fgroup', 'biaya', 'pelunasan'),
                     'numbercell'=> array('pelunasan')
                );
            }
            if ($groupbysql == 'thblbayar') {
                $retval = array(
                    'head' => array('Tanggal Bayar', 'Jenis_Biaya', 'Biaya', 'Pelunasan'),
                    'wh' => array(30, 80, 30, 30),
                    'border' => array('TBL', 'TBL', 'TBL', 1),
                    'align' => array('C', 'L', 'L', 'R'),
                    'keys' => array('tglbayar', 'fgroup', 'biaya', 'pelunasan'),
                     'numbercell'=> array('pelunasan')
                );
            }
            if ($groupbysql == 'thbl') {
                $retval = array(
                    'head' => array('Jenis_Biaya', 'Tanggal Bayar', 'Biaya', 'Pelunasan'),
                    'wh' => array(80, 30, 30, 30),
                    'border' => array('TBL', 'TBL', 'TBL', 1),
                    'align' => array('L',  'C', 'L', 'R'),
                    'keys' => array('fgroup', 'tglbayar', 'biaya', 'pelunasan'),
                     'numbercell'=> array('pelunasan')
                );
            }
        } else {
            $retval = array('Tglbayar', 'Rekening', 'Nama Rekening', 'Thbl', 'Nis', 'Nama', 'Kelas', 'Semester', 'Keterangan', 'Jenis_Biaya', 'Biaya', 'Pelunasan', 'Trx_Id', 'Trx_Id_Bank', 'Teller_Bank', 'Catat_by');
            array_push($retval, array(20, 35, 15, 15, 35, 15, 10, 30, 30, 30, 25, 15, 15, 15, 15, 15));
        }
        return $retval;
    }

    public function create_pdf($data, $groupbysql) {
        $this->AddPage('P');
        $setting = $this->get_header_column($groupbysql);
        $this->hfill = 4;
        $totalcount = 0;
        $totalcount1 = 0;
        $grouby = '';
        $grouby1 = '';
        $rowcount=0;$rowcount1=0;
        $total=0;
        $total1=0;
        foreach ($data as $value) {
            if ($groupbysql == 'rekening') {
                if ($grouby != $value->no_rek) {
                    $grouby = $value->no_rek;
                    $this->SetFont('Arial', 'B', 8);
                    $this->SetX(3);
                    if($this->GetY()+($this->hfill*2)>272){
                        $this->AddPage('P');
                    }
                    $this->Cell(125, $this->hfill, ' Rekening : ' . $value->no_rek . ' [' . $value->nama_rek . ']', 0, 0, 'L');
                    $this->Ln();
                    $totalcount = 0;
                    $rowcount=0;
                    $total=0;
                    
                    $this->set_header_column($setting['head'], $setting['wh']);
                }
                $where = array('no_rek' => $value->no_rek);
                $totalcount = $this->getcount_data($data, $where);
                $total +=$value->pelunasan;
                $rowcount++;
                $colcount = 0;
                $this->SetFont('Arial', '', 8);
                
                foreach ($value as $key => $v) {
                    if($this->GetY()+$this->hfill>272){
                        $this->AddPage('P');
                        $this->set_header_column($setting['head'], $setting['wh']);
                    }                    
                    
                    
                    foreach ($setting['keys'] as $kk) {
                        if ($kk == $key) {
                            if(in_array($kk, $setting['numbercell'])){
                                $this->Cell($setting['wh'][$colcount], $this->hfill, (is_numeric($v))?number_format($v):$v, $setting['border'][$colcount], 0, $setting['align'][$colcount]);
                            }else{
                                $this->Cell($setting['wh'][$colcount], $this->hfill, $v, $setting['border'][$colcount], 0, $setting['align'][$colcount]);
                            }
                            
                            
                            $colcount++;
                        }
                    }
                }
                $this->Ln();
                if ($rowcount==$totalcount){
                    if($this->GetY()+$this->hfill>272){
                        $this->AddPage('P');
                    }    
                    $this->SetFont('Arial', 'B', 8);
                    $totalvalue=array('biaya'=>'Total','pelunasan'=>$total);
                   
                    $colcount=0;
                    foreach ($setting['keys'] as $kk){
                        if(array_key_exists($kk,$totalvalue)){
                            $this->Cell($setting['wh'][$colcount], $this->hfill, (is_numeric($totalvalue[$kk]))?number_format($totalvalue[$kk]):$totalvalue[$kk], 1, 0, $setting['align'][$colcount]);
                        }else{
                            $this->Cell($setting['wh'][$colcount], $this->hfill, '', 0, 0, $setting['align'][$colcount]);
                        }
                        $colcount++;
                    }
                    $this->Ln();
                    $this->Ln();
                }
                
            }
            if ($groupbysql == 'jenis') {
                if ($grouby != $value->fgroup) {
                    if($this->GetY()+($this->hfill*2)>272){
                        $this->AddPage('P');
                    }    
                    $grouby = $value->fgroup;
                    $this->SetFont('Arial', 'B', 8);
                    $this->SetX(3);
                    $this->Cell(125, $this->hfill, $value->fgroup . ' [' . $value->nama_rek . ']', 0, 0, 'L');
                    $this->Ln();
                    $totalcount = 0;
                    $rowcount=0;
                    $total=0;
                    $this->set_header_column($setting['head'], $setting['wh']);
                }
                $where = array('fgroup' => $value->fgroup);
                $totalcount = $this->getcount_data($data, $where);
                $total +=$value->pelunasan;
                $rowcount++;
                $colcount = 0;
                $this->SetFont('Arial', '', 8);
                foreach ($value as $key => $v) {
                    if($this->GetY()+$this->hfill>272){
                        $this->AddPage('P');
                        $this->set_header_column($setting['head'], $setting['wh']);
                    }    
                    
                    foreach ($setting['keys'] as $kk) {
                        if ($kk == $key) {
                            if(in_array($kk, $setting['numbercell'])){
                                $this->Cell($setting['wh'][$colcount], $this->hfill, (is_numeric($v))?number_format($v):$v, $setting['border'][$colcount], 0, $setting['align'][$colcount]);
                            }else{
                                $this->Cell($setting['wh'][$colcount], $this->hfill, $v, $setting['border'][$colcount], 0, $setting['align'][$colcount]);
                            }
                            
                            
                            $colcount++;
                        }
                    }
                }
                $this->Ln();
                if ($rowcount==$totalcount){
                    if($this->GetY()+$this->hfill>272){
                        $this->AddPage('P');
                    }    
                    
                    $this->SetFont('Arial', 'B', 8);
                    $totalvalue=array('biaya'=>'Total','pelunasan'=>$total);
                   
                    $colcount=0;
                    foreach ($setting['keys'] as $kk){
                        if(array_key_exists($kk,$totalvalue)){
                            $this->Cell($setting['wh'][$colcount], $this->hfill, (is_numeric($totalvalue[$kk]))?number_format($totalvalue[$kk]):$totalvalue[$kk], 1, 0, $setting['align'][$colcount]);
                        }else{
                            $this->Cell($setting['wh'][$colcount], $this->hfill, '', 0, 0, $setting['align'][$colcount]);
                        }
                        $colcount++;
                    }
                    $this->Ln();
                    $this->Ln();
                }
                
            }
            if ($groupbysql == 'tglbayar') {
                if ($grouby != $value->tglbayar) {
                    if($this->GetY()+($this->hfill*3)>272){
                        $this->AddPage('P');
                    }    
                    
                    $grouby = $value->tglbayar;
                    $this->SetFont('Arial', 'B', 8);
                    $this->SetX(3);
                    $this->Cell(125, $this->hfill, 'Tanggal Bayar : '. $value->tglbayar , 0, 0, 'L');
                    $this->Ln();
//                    $totalcount = 0;
                    $rowcount=0;
                    $total=0;
                    
                    $where = array('tglbayar' => $value->tglbayar);
                    $totalcount = $this->getcount_data($data, $where);
                }
                
                $total +=$value->pelunasan;
                $rowcount++;
//                $colcount = 0;
                
                if ($grouby1 != $value->no_rek) {
                    if($this->GetY()+($this->hfill*2)>272){
                        $this->AddPage('P');
                    }    
                    
                    $grouby1 = $value->no_rek;
                    $where1 = array('tglbayar' => $value->tglbayar,'no_rek'=>$value->no_rek);
                    $totalcount1 = $this->getcount_data($data, $where1);
                    
                    $this->SetFont('Arial', 'I', 8);
                    $this->SetX(3);
                    $this->Cell(125, $this->hfill,'Rekening : '. $value->no_rek. ' [' . $value->nama_rek . ']' , 0, 0, 'L');
                    $this->Ln();
//                    $totalcount1 = 0;
                    $rowcount1=0;
                    $total1=0;
                    $this->set_header_column($setting['head'], $setting['wh']);
                    
                }
                
                
                $total1 += $value->pelunasan;
                $rowcount1++;
                $colcount = 0;
                $this->SetFont('Arial', '', 8);
                foreach ($value as $key => $v) {
                    if($this->GetY()+$this->hfill>272){
                        $this->AddPage('P');
                        $this->set_header_column($setting['head'], $setting['wh']);
                    }    
                    
                    foreach ($setting['keys'] as $kk) {
                        if ($kk == $key) {
                            if(in_array($kk, $setting['numbercell'])){
                                $this->Cell($setting['wh'][$colcount], $this->hfill, (is_numeric($v))?number_format($v):$v, $setting['border'][$colcount], 0, $setting['align'][$colcount]);
                            }else{
                                $this->Cell($setting['wh'][$colcount], $this->hfill, $v, $setting['border'][$colcount], 0, $setting['align'][$colcount]);
                            }
                            
                            
                            $colcount++;
                        }
                    }
                }
                $this->Ln();
                if ($rowcount1==$totalcount1){
                    if($this->GetY()+($this->hfill*2)>272){
                        $this->AddPage('P');
                    }    
                    
                    $this->SetFont('Arial', 'B', 8);
                    $totalvalue=array('biaya'=>'Total','pelunasan'=>$total1);
                   
                    $colcount=0;
                    foreach ($setting['keys'] as $kk){
                        if(array_key_exists($kk,$totalvalue)){
                            $this->Cell($setting['wh'][$colcount], $this->hfill, (is_numeric($totalvalue[$kk]))?number_format($totalvalue[$kk]):$totalvalue[$kk], 1, 0, $setting['align'][$colcount]);
                        }else{
                            $this->Cell($setting['wh'][$colcount], $this->hfill, '', 0, 0, $setting['align'][$colcount]);
                        }
                        $colcount++;
                    }
                    $this->Ln();
//                    $this->Ln();
                }
                
                if ($rowcount==$totalcount){
                    if($this->GetY()+$this->hfill>272){
                        $this->AddPage('P');
                    }    
                    
                    $this->SetFont('Arial', 'B', 8);
                    $totalvalue=array('biaya'=>'Total '.$value->tglbayar,'pelunasan'=>$total);
                   
                    $colcount=0;
                    foreach ($setting['keys'] as $kk){
                        if(array_key_exists($kk,$totalvalue)){
                            $this->Cell($setting['wh'][$colcount], $this->hfill, (is_numeric($totalvalue[$kk]))?number_format($totalvalue[$kk]):$totalvalue[$kk], 1, 0, $setting['align'][$colcount]);
                        }else{
                            $this->Cell($setting['wh'][$colcount], $this->hfill, '', 0, 0, $setting['align'][$colcount]);
                        }
                        $colcount++;
                    }
                    $this->Ln();
                    $this->Ln();
                }
                
            }
            if ($groupbysql == 'thblbayar') {
                
                if ($grouby != $value->thblbayar) {
                    if($this->GetY()+($this->hfill*3)>272){
                        $this->AddPage('P');
                    }    
                    
                    $grouby = $value->thblbayar;
                    $this->SetFont('Arial', 'B', 8);
                    $this->SetX(3);
                    $this->Cell(125, $this->hfill, 'ThBl Bayar : '. $this->getthbl($value->thblbayar) , 0, 0, 'L');
                    $this->Ln();
//                    $totalcount = 0;
                    $rowcount=0;
                    $total=0;
                    
                    $where = array('thblbayar' => $value->thblbayar);
                    $totalcount = $this->getcount_data($data, $where);
                }
                
                $total +=$value->pelunasan;
                $rowcount++;
//                $colcount = 0;
                
                if ($grouby1 != $value->no_rek) {
                    if($this->GetY()+($this->hfill*2)>272){
                        $this->AddPage('P');
                    }   
                    $grouby1 = $value->no_rek;
                    $where1 = array('thblbayar' => $value->thblbayar,'no_rek'=>$value->no_rek);
                    $totalcount1 = $this->getcount_data($data, $where1);
                    
                    $this->SetFont('Arial', 'I', 8);
                    $this->SetX(3);
                    $this->Cell(125, $this->hfill,'Rekening : '. $value->no_rek. ' [' . $value->nama_rek . ']' , 0, 0, 'L');
                    $this->Ln();
//                    $totalcount1 = 0;
                    $rowcount1=0;
                    $total1=0;
                    $this->set_header_column($setting['head'], $setting['wh']);
                    
                    
                }
                
                
                $total1 += $value->pelunasan;
                $rowcount1++;
                $colcount = 0;
                $this->SetFont('Arial', '', 8);
                foreach ($value as $key => $v) {
                    if($this->GetY()+$this->hfill>272){
                        $this->AddPage('P');
                        $this->set_header_column($setting['head'], $setting['wh']);
                    } 
                    foreach ($setting['keys'] as $kk) {
                        if ($kk == $key) {
                            if(in_array($kk, $setting['numbercell'])){
                                $this->Cell($setting['wh'][$colcount], $this->hfill, (is_numeric($v))?number_format($v):$v, $setting['border'][$colcount], 0, $setting['align'][$colcount]);
                            }else{
                                $this->Cell($setting['wh'][$colcount], $this->hfill, $v, $setting['border'][$colcount], 0, $setting['align'][$colcount]);
                            }
                            
                            
                            $colcount++;
                        }
                    }
                }
                $this->Ln();
                if ($rowcount1==$totalcount1){
                    if($this->GetY()+($this->hfill*2)>272){
                        $this->AddPage('P');
                    } 
                    $this->SetFont('Arial', 'B', 8);
                    $totalvalue=array('biaya'=>'Total','pelunasan'=>$total1);
                   
                    $colcount=0;
                    foreach ($setting['keys'] as $kk){
                        if(array_key_exists($kk,$totalvalue)){
                            $this->Cell($setting['wh'][$colcount], $this->hfill, (is_numeric($totalvalue[$kk]))?number_format($totalvalue[$kk]):$totalvalue[$kk], 1, 0, $setting['align'][$colcount]);
                        }else{
                            $this->Cell($setting['wh'][$colcount], $this->hfill, '', 0, 0, $setting['align'][$colcount]);
                        }
                        $colcount++;
                    }
                    $this->Ln();
//                    $this->Ln();
                }
                
                if ($rowcount==$totalcount){
                    if($this->GetY()+$this->hfill>272){
                        $this->AddPage('P');
                    } 
                    
                    $this->SetFont('Arial', 'B', 8);
                    $totalvalue=array('biaya'=>'Total '.$this->getthbl($value->thblbayar),'pelunasan'=>$total);
                   
                    $colcount=0;
                    foreach ($setting['keys'] as $kk){
                        if(array_key_exists($kk,$totalvalue)){
                            $this->Cell($setting['wh'][$colcount], $this->hfill, (is_numeric($totalvalue[$kk]))?number_format($totalvalue[$kk]):$totalvalue[$kk], 1, 0, $setting['align'][$colcount]);
                        }else{
                            $this->Cell($setting['wh'][$colcount], $this->hfill, '', 0, 0, $setting['align'][$colcount]);
                        }
                        $colcount++;
                    }
                    $this->Ln();
                    $this->Ln();
                }
                
            }
            if ($groupbysql == 'thbl') {
                if ($grouby != $value->thbl) {
                    if($this->GetY()+($this->hfill*3)>272){
                        $this->AddPage('P');
                    } 
                    $grouby = $value->thbl;
                    $this->SetFont('Arial', 'B', 8);
                    $this->SetX(3);
                    $this->Cell(125, $this->hfill, 'ThBl Periode : '. $this->getthbl($value->thbl), 0, 0, 'L');
                    $this->Ln();
//                    $totalcount = 0;
                    $rowcount=0;
                    $total=0;
                    
                    $where = array('thbl' => $value->thbl);
                    $totalcount = $this->getcount_data($data, $where);
                }
                
                $total +=$value->pelunasan;
                $rowcount++;
//                $colcount = 0;
                
                if ($grouby1 != $value->fgroup) {
                    if($this->GetY()+($this->hfill*2)>272){
                        $this->AddPage('P');
                    } 
                    
                    $grouby1 = $value->fgroup;
                    $where1 = array('thbl' => $value->thbl,'fgroup'=>$value->fgroup);
                    $totalcount1 = $this->getcount_data($data, $where1);
                    
                    $this->SetFont('Arial', 'I', 8);
                    $this->SetX(3);
                    $this->Cell(125, $this->hfill,$value->fgroup, 0, 0, 'L');
                    $this->Ln();
//                    $totalcount1 = 0;
                    $rowcount1=0;
                    $total1=0;
                    $this->set_header_column($setting['head'], $setting['wh']);
                    
                    
                }
                
                
                $total1 += $value->pelunasan;
                $rowcount1++;
                $colcount = 0;
                $this->SetFont('Arial', '', 8);
                foreach ($value as $key => $v) {
                    if($this->GetY()+($this->hfill*2)>272){
                        $this->AddPage('P');
                        $this->set_header_column($setting['head'], $setting['wh']);
                    } 
                    foreach ($setting['keys'] as $kk) {
                        if ($kk == $key) {
                            if(in_array($kk, $setting['numbercell'])){
                                $this->Cell($setting['wh'][$colcount], $this->hfill, (is_numeric($v))?number_format($v):$v, $setting['border'][$colcount], 0, $setting['align'][$colcount]);
                            }else{
                                $this->Cell($setting['wh'][$colcount], $this->hfill, $v, $setting['border'][$colcount], 0, $setting['align'][$colcount]);
                            }
                            
                            
                            $colcount++;
                        }
                    }
                }
                $this->Ln();
                if ($rowcount1==$totalcount1){
                    if($this->GetY()+($this->hfill*2)>272){
                        $this->AddPage('P');
                    } 
                    
                    $this->SetFont('Arial', 'B', 8);
                    $totalvalue=array('biaya'=>'Total','pelunasan'=>$total1);
                   
                    $colcount=0;
                    foreach ($setting['keys'] as $kk){
                        if(array_key_exists($kk,$totalvalue)){
                            $this->Cell($setting['wh'][$colcount], $this->hfill, (is_numeric($totalvalue[$kk]))?number_format($totalvalue[$kk]):$totalvalue[$kk], 1, 0, $setting['align'][$colcount]);
                        }else{
                            $this->Cell($setting['wh'][$colcount], $this->hfill, '', 0, 0, $setting['align'][$colcount]);
                        }
                        $colcount++;
                    }
                    $this->Ln();
//                    $this->Ln();
                }
                
                if ($rowcount==$totalcount){
                    if($this->GetY()+$this->hfill>272){
                        $this->AddPage('P');
                    } 
                    
                    $this->SetFont('Arial', 'B', 8);
                    $totalvalue=array('biaya'=>'Total '.$this->getthbl($value->thbl),'pelunasan'=>$total);
                   
                    $colcount=0;
                    foreach ($setting['keys'] as $kk){
                        if(array_key_exists($kk,$totalvalue)){
                            $this->Cell($setting['wh'][$colcount], $this->hfill, (is_numeric($totalvalue[$kk]))?number_format($totalvalue[$kk]):$totalvalue[$kk], 1, 0, $setting['align'][$colcount]);
                        }else{
                            $this->Cell($setting['wh'][$colcount], $this->hfill, '', 0, 0, $setting['align'][$colcount]);
                        }
                        $colcount++;
                    }
                    $this->Ln();
                    $this->Ln();
                }
                
            }
        }
    }

}

?>
